# -- coding: utf-8 --

# file = open('test.txt')
# # while True:
# #     line = file.readline()
# #     if line == '':
# #         break
# #     print(line,end='')
# # file.close()
#
# for i in file:
#     print(i,end='')


# def copy(sourcePath,targetPath):
#     sourceFd = open(sourcePath,'r')
#     targetFd = open(targetPath,'w')
#     for line in sourceFd:
#         targetFd.write(line)
#     sourceFd.close()
#     targetFd.close()
#
# copy('test.txt','123.txt')

'''
编写一个用于记录日志的函数 log(msg)，该函数将 msg 写入到日志文件 log.txt 中。每次写日志文件时，需要：

* 保留日志文件的原有内容
* 将新的记录添加到日志文件的尾部
'''

from datetime import  *

def log(msg):
    dt = datetime.today()
    now = dt.strftime("%Y-%m-%d %H:%M:%S")
    line = '%s : %s\n' % (now,msg)
    logfile.write(line)

logfile = open('test.txt','a')
log('nm')
log('nmdd')
logfile.close()